package com.company.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author lcl
 * @Title: OrderUtils
 * @ProjectName smart-planet
 * @Description: 订单相关
 * @date 2019/1/29下午3:10
 */
public class OrderUtils {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    //2016.7.18 时间戳
    private static long BASE_TIME_STAMP = 1468771200000L;
    /**
     * 生成订单编号
     * @return
     */
    public static String getOrderNumber() {
        return "CG-" + getDateTimeString() + getVerificationCode(6);
    }
    /**
     * 生成退单编号
     */
    public static String getOrderAftersalesNumber() {
        return "SH-" + getDateTimeString() + getVerificationCode(6);
    }

    /**
     * 生成日期String
     */
    private static String getDateTimeString() {
        Date current = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmm");
        String dateTime = format.format(current);
        return dateTime;
    }
    /**
     * 生成一个随机六位数
     * @param num 位数
     * @return
     */
    public static int getVerificationCode(int num) {
        Double size = Math.pow(10, num);
        int i = (int) (Math.random() * size);
        return i > size / 10 ? i : getVerificationCode(num);
    }
}
